/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com 

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef TRI_MATRIX_H_
#define TRI_MATRIX_H_

#include "vector.h"
#include "utils.h"
#include <math.h>
#include <iostream>


namespace tri
{

class TMatrix
{
    friend std::ostream &operator<<( std::ostream&, const TMatrix&);
    
public:
    TMatrix();
    TMatrix(const float* elements);
    virtual ~TMatrix();
   
    float elements[16];  
};

/**load a 4x4 TMatrix identity TMatrix 
        
@param m: target TMatrix
*/
void loadIdentity(tri::TMatrix* m);

/**
 * Translate a given TMatrix
 * 
 *@param m target TMatrix
 *@param x: x value
 *@param y: y value
 *@param z: z value
 */
void translate(TMatrix* m,float x,float y,float z);

/**
 * load a rotation TMatrix
 * 
 * @param rot : Rotation in degrees
 * @param m : Target TMatrix 
 */
void getRotationMatrixX(float rot,TMatrix*m);

/**
 * load a rotation TMatrix
 * 
 * @param rot : Rotation in degrees
 * @param m : Target TMatrix 
 */
void getRotationMatrixY(float rot,TMatrix*m);

/**
 * load a rotation TMatrix
 * 
 * @param rot : Rotation in degrees
 * @param m : Target TMatrix 
 */
void getRotationMatrixZ(float rot,TMatrix*m);

/**
 * load a rotation TMatrix
 * 
 * @param rot : Rotation in degrees
 * @param m : Target TMatrix 
 */
void getRotationMatrixXYZ(float x,float y,float z,TMatrix*m);
/**Calculate the product of 2 TMatrix 
    
@param m1: Matrix 1
@param m2: Matrix 2 
@param dst: Product of m1 and m2
*/
void multMat(const TMatrix*m1,const TMatrix*m2,TMatrix*dst);

/**Calculate the product of a TMatrix and a TVector 
    
@param m: Matrix
@param v: Vector
@param dst: Product of m and v
*/
void multVMat(const TMatrix* m,const TVector* v,TVector* dst);

/**Calculate the invert of a 3x3 TMatrix 
        
@param m: Matrix
*/
void invert(float m[9]);

/**
 * Get the 3x3 rotation TMatrix from a TMatrix
 */
void get3x3MatrixFromMatrix(const TMatrix* mat,float m[9]);

void getMatrixFrom3x3Matrix(const float m[9],TMatrix* mat);



}

#endif /*MATRIX_H_*/
